package com.zzq.demo.retry;

import com.github.rholder.retry.RetryException;
import com.github.rholder.retry.Retryer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: zhaoziqian
 * @description: TODO
 * @date: 2019/10/21 10:01 下午
 **/
@Slf4j
@Component
public class ScheduledTasks {

    private static AtomicInteger count = new AtomicInteger(0);

    @Resource
    private JobHander hander;

    @Resource
    private MyRetryerBuilder builder;

    /**
     * 同步商品价格定时任务
     *
     * @throws Exception
     * @Scheduled(fixedDelay = 30000) ：上一次执行完毕时间点之后30秒再执行
     */
    @Scheduled(fixedDelay = 1 * 1000)
    public void task() throws Exception {
        System.out.println();
        System.out.println();
        log.info("任务开始执行 ： 》》》  " + count.incrementAndGet());
        System.out.println();
        System.out.println();
        Retryer retryer = builder.build();
        retryer.call(hander);
    }
}
